package com.gopay.common.cps.manager.auosettle.impl;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.gopay.common.cps.manager.auosettle.AutoSettleDailyStatsAssembleVOManager;
import com.gopay.common.domain.autosettle.bo.AutoSettleBankDailyStatsBO;
import com.gopay.common.domain.autosettle.vo.AutoSettleBankDailyStatsVO;


/** 
 * @fileName  AutoSettleDailyStatsAssembleVOManagerImpl.java
 * @author  张建龙 
 * @date 创建时间：2016年1月21日 上午11:26:06
 */
@Service("autoSettleDailyStatsAssembleVOManager")
public class AutoSettleDailyStatsAssembleVOManagerImpl implements AutoSettleDailyStatsAssembleVOManager {

	@Override
	public List<AutoSettleBankDailyStatsVO> buildVoFromAsDailyStatsBo(
			List<AutoSettleBankDailyStatsBO> autoSettleBankDailyStatsBOList) {
		List<AutoSettleBankDailyStatsVO> autoSettleBankDailyStatsVOList = new ArrayList<AutoSettleBankDailyStatsVO>();
		//DecimalFormat decimalFormat = new DecimalFormat("############.##");
		for (AutoSettleBankDailyStatsBO bo :autoSettleBankDailyStatsBOList) {
			AutoSettleBankDailyStatsVO vo = new AutoSettleBankDailyStatsVO();
			
			vo.setFieldName(bo.getFieldName());
			
			BigDecimal mondayAmt = bo.getMondayAmt();
			String mondayAmtStr = null;
			if(null!=mondayAmt){
				mondayAmtStr = mondayAmt.setScale(2, RoundingMode.HALF_UP).toString();
			}
			
			BigDecimal tuesdayAmt = bo.getTuesdayAmt();
			String tuesdayAmtStr = null;
			if(null!=tuesdayAmt){
				tuesdayAmtStr = tuesdayAmt.setScale(2, RoundingMode.HALF_UP).toString();
			}
			
			BigDecimal wednesdayAmt = bo.getWednesdayAmt();
			String wednesdayAmtStr = null;
			if(null!=wednesdayAmt){
				wednesdayAmtStr = wednesdayAmt.setScale(2, RoundingMode.HALF_UP).toString();
			}
			
			BigDecimal thursdayAmt = bo.getThursdayAmt();
			String thursdayAmtStr = null;
			if(null!=thursdayAmt){
				thursdayAmtStr = thursdayAmt.setScale(2, RoundingMode.HALF_UP).toString();
			}
			
			BigDecimal fridayAmt = bo.getFridayAmt();
			String fridayAmtStr = null;
			if(null!=fridayAmt){
				fridayAmtStr = fridayAmt.setScale(2, RoundingMode.HALF_UP).toString();
			}
			
			BigDecimal saturdayAmt = bo.getSaturdayAmt();
			String saturdayAmtStr = null;
			if(null!=saturdayAmt){
				saturdayAmtStr = saturdayAmt.setScale(2, RoundingMode.HALF_UP).toString();
			}
			
			BigDecimal sundayAmt = bo.getSundayAmt();
			String sundayAmtStr = null;
			if(null!=sundayAmt){
				sundayAmtStr = sundayAmt.setScale(2, RoundingMode.HALF_UP).toString();
			}
		
			vo.setMondayAmt(mondayAmtStr);
			vo.setTuesdayAmt(tuesdayAmtStr);
			vo.setWednesdayAmt(wednesdayAmtStr);
			vo.setThursdayAmt(thursdayAmtStr);
			vo.setFridayAmt(fridayAmtStr);
			vo.setSaturdayAmt(saturdayAmtStr);
			vo.setSundayAmt(sundayAmtStr);
			
			BigDecimal sumAmt = bo.getSumAmt();
			String sumAmtStr = null;
			if(null!=sumAmt){
				sumAmtStr = sumAmt.setScale(2, RoundingMode.HALF_UP).toString();
			}
			
			BigDecimal peakAmt = bo.getPeakAmt();
			String peakAmtStr = null;
			if(null!=peakAmt){
				peakAmtStr = peakAmt.setScale(2, RoundingMode.HALF_UP).toString();
			}
			
			BigDecimal avgAmt = bo.getAvgAmt();
			String avgAmtStr = null;
			if(null!=avgAmt){
				avgAmtStr = avgAmt.setScale(2, RoundingMode.HALF_UP).toString();
			}
			
			vo.setSumAmt(sumAmtStr);
			vo.setPeakAmt(peakAmtStr);
			vo.setAvgAmt(avgAmtStr);
			
			autoSettleBankDailyStatsVOList.add(vo);
		}
		return autoSettleBankDailyStatsVOList;
	}

	@Override
	public int caculateShowColumns(List<AutoSettleBankDailyStatsVO> autoSettleBankDailyStatsVOList) {
		int flag = 0;
		if(autoSettleBankDailyStatsVOList==null){
			return flag =124;
		}
		for (AutoSettleBankDailyStatsVO autoSettleBankDailyStatsVO : autoSettleBankDailyStatsVOList) {
			if(StringUtils.isNotEmpty(autoSettleBankDailyStatsVO.getMondayAmt())){
				flag=flag|64;
			}
			if(StringUtils.isNotEmpty(autoSettleBankDailyStatsVO.getTuesdayAmt())){
				flag=flag|32;
			}
			if(StringUtils.isNotEmpty(autoSettleBankDailyStatsVO.getWednesdayAmt())){
				flag=flag|16;
			}
			if(StringUtils.isNotEmpty(autoSettleBankDailyStatsVO.getThursdayAmt())){
				flag=flag|8;
			}
			if(StringUtils.isNotEmpty(autoSettleBankDailyStatsVO.getFridayAmt())){
				flag=flag|4;
			}
			if(StringUtils.isNotEmpty(autoSettleBankDailyStatsVO.getSaturdayAmt())){
				flag=flag|2;
			}
			if(StringUtils.isNotEmpty(autoSettleBankDailyStatsVO.getSundayAmt())){
				flag=flag|1;
			}
		}
		return flag;
	}

}
